import {

  getToEmail
} from '../../utils/api.common'

Page({

  data: {
    list: [],
    show: false,
    modelId: null,
    toUser: null,
  },

  submit(e) {
    this.setData({
      modelId: e.currentTarget.dataset.id,
      show: true
    })
  },
  toDetail(e){
    // wx.showToast({
    //   title: '暂未开放',
    //   icon: "none",
    //   mask: false,
    //   duration: 1500
    // })
    wx.navigateTo({
      url: '../detail/detail?id=' + e.currentTarget.dataset.id
    })
  },
  close() {
    this.setData({
      show: false,
      toUser: null
    })
  },

  // 确认
  confirm() {
    if (!this.data.toUser) {
      return wx.showToast({
        title: '请输入邮箱',
        icon: "none",
        mask: false,
        duration: 1500
      })

    }
    let params = {
      modelId: this.data.modelId,
      toUser: this.data.toUser,
    }
    getToEmail(params).then(res => {
      if (res.code === 200) {
        wx.showToast({
          title: '邮件发送成功',
          icon: "none",
          mask: false,
          duration: 1500
        })
        this.close()
      }
    })
  },

  // 绑定型号
  inputToUser(e) {
    this.setData({
      toUser: e.detail.value
    })
  },

  onLoad(options) {
    let list = JSON.parse(options.list)
    this.setData({
      list: list
    })
  },


})